package com.sgb.kjwl.view.ui.fragment.packers;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.util.Pair;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.bumptech.glide.Glide;
import com.google.android.material.tabs.TabLayout;
import com.sgb.alimaplibrary.util.ToastUtil;
import com.sgb.kjwl.AppFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FragmentPackerAttentionDetailBinding;
import com.sgb.kjwl.model.entity.EmploymentEntity;
import com.sgb.kjwl.model.entity.FindPackersEntity;
import com.sgb.kjwl.model.entity.FindPeopleEntity;
import com.sgb.kjwl.model.entity.TeamPriceItemEntity;
import com.sgb.kjwl.model.entity.packers.EngineeringCompanyEntity;
import com.sgb.kjwl.model.entity.packers.LabourServiceAndEmploymentEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.utils.NumberConstant;
import com.sgb.kjwl.view.ui.activity.WebViewX5HostActivity;
import com.sgb.kjwl.view.ui.activity.manage.WebsiteInfoActivity;
import com.sgb.kjwl.view.ui.activity.packers.EmploymentDetailActivity;
import com.sgb.kjwl.view.ui.activity.packers.FindPeopleDetailActivity;
import com.sgb.kjwl.view.ui.activity.packers.LaborServiceAndEmploymentDetailActivity;
import com.sgb.kjwl.view.ui.activity.packers.TeamOfferDetailActivity;
import com.sgb.kjwl.view.ui.activity.self.mine.IntelligentAttentionActivity;
import com.sgb.kjwl.view.ui.adapter.packers.EngineeringCompanyAdapter;
import com.sgb.kjwl.view.ui.adapter.packers.FindPackersAdapter;
import com.sgb.kjwl.view.ui.adapter.packers.FindPeopleAdapter;
import com.sgb.kjwl.view.ui.adapter.packers.LaborServiceAndEmploymentAdapter;
import com.sgb.kjwl.view.ui.adapter.packers.PackersEmploymentAdapter;
import com.sgb.kjwl.view.ui.adapter.price.QuotePriceListAdapter;
import com.sgb.kjwl.viewmodel.packers.PackerAttentionDetailViewModel;
import com.sgb.link.router.PathTeam;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.xrecyclerview.XRecyclerView;

import org.jetbrains.annotations.NotNull;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
 * @author : younghow
 * @date : 2021/7/12 17:10
 * description : 工队智能关注列表
 * first:这里因为设计在一起的，包含了七个列表，所以在参数和方法数略显繁杂
 */
public class PackerAttentionDetailFragment extends AppFragment {

    FragmentPackerAttentionDetailBinding mBinding;
    PackerAttentionDetailViewModel mViewModel;
    /**
     * 下面这几个是判断页面是否正在执行加载更多的操作的判断依据，作为后面设置adapter的一个依据
     * isLoadMore 判断劳务用工
     * isLoadMoreCompany 判断工程公司
     * isLoadMoreTeamBuild 判断施工工队
     * isLoadMoreTeamClassGroup 判断班组工队
     * isLoadMoreWorker 判断工人关注
     * isLoadMoreTemporaryEmployment 判断临时用工关注
     * isLoadMoreQuotePrice 判断工种报价关注
     */
    private boolean isLoadMore;
    private boolean isLoadMoreCompany;
    private boolean isLoadMoreTeamBuild;
    private boolean isLoadMoreTeamClassGroup;
    private boolean isLoadMoreWorker;
    private boolean isLoadMoreTemporaryEmployment;
    private boolean isLoadMoreQuotePrice;

    /**
     * 下面这几个是判断页数的依据
     * page 判断劳务用工
     * pageCompany 判断工程公司
     * pageTeamBuild 判断施工工队
     * pageTeamClassGroup 判断班组工队
     * pageTeamWorker 判断工人关注
     * pageTemporaryEmployment 临时用工关注
     * pageQuotePrice 工种报价关注
     */
    private int page = 1;
    private int pageCompany = 1;
    private int pageTeamBuild = 1;
    private int pageTeamClassGroup = 1;
    private int pageWorker = 1;
    private int pageTemporaryEmployment  = 1;
    private int pageQuotePrice = 1;

    /**
     * 下面的这几个是这些列表的adapter
     * mAdapter 劳务用工
     * adapterCompany 工程公司
     * findPackersClassGroupAdapter 班组工队
     * findPackersBuildAdapter 施工工队
     * adapter 临时用工
     * adapterQuotePrice 工种报价
     */
    private LaborServiceAndEmploymentAdapter mAdapter;
    private EngineeringCompanyAdapter adapterCompany;
    private FindPackersAdapter findPackersClassGroupAdapter;
    private FindPackersAdapter findPackersBuildAdapter;
    private FindPeopleAdapter findPeopleAdapter;
    private PackersEmploymentAdapter adapter;
    private QuotePriceListAdapter adapterQuotePrice;
    /**
     * 这个是包含了两个tab的选中的position,当初设计的时候认为第一级有次级tab，其余的没有，所以把下面的次级当成了前两级，后面的依次往后推，也就是当前选中+1
     */
    private int mTabPage = 0;

    public static PackerAttentionDetailFragment newInstance(){
        return new PackerAttentionDetailFragment();
    }

    @Nullable
    @Override
    public View onCreateView(@NotNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_packer_attention_detail, container, false);
        return mBinding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull @NotNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        mBinding.setLifecycleOwner(this);
        mViewModel = new ViewModelProvider(this).get(PackerAttentionDetailViewModel.class);

        initAdapter();
        initData();
        initTabLayout();
        initRecyclerView();
        initLiveData();
        setAdapterForTab(0);
    }

    private void initAdapter() {
        setCompanyAdapter();
        setLaborAdapter();
        setBuildAdapter();
        setClassGroupAdapter();
        setWorkerAdapter();
        setTemporaryEmploymentAdapter();
        setJobTypeQuotationAdapter();
    }

    private void initData() {
        loadDataForTab(0,false);
    }

    /**
     * 初始化tabLayout
     */
    private void initTabLayout() {
        //本地viewModel的数据，加载在一级tab上
        for (String s : mViewModel.firstTitle()) {
            mBinding.tlMainTitle.addTab(mBinding.tlMainTitle.newTab().setText(s));
        }
        //本地viewModel的数据，加载在二级tab上
        for (String s : mViewModel.secondTitle()) {
            mBinding.tlSecondTitle.addTab(mBinding.tlSecondTitle.newTab().setText(s));
        }

        //这里需要设置选择来请求网络和更新参数，所以在这里设置监听
        mBinding.tlMainTitle.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                if (tab.getPosition() != 0){
                    mTabPage = tab.getPosition()+1;
                    mBinding.llTag.setVisibility(View.GONE);
                }else {
                    mBinding.tlSecondTitle.postDelayed(() -> mBinding.tlSecondTitle.setScrollPosition(0,0,true),100);
                    mTabPage = 0;
                    mBinding.llTag.setVisibility(View.VISIBLE);
                }

                loadDataForTab(mTabPage,false);
                setAdapterForTab(mTabPage);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        mBinding.tlSecondTitle.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                mTabPage = tab.getPosition();
                setAdapterForTab(mTabPage);
                loadDataForTab(mTabPage,false);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    private void initLiveData() {
        setLaborListLiveData();
        setCompanyListLiveData();
        setStatusLiveData();
        setStateLiveData();
        setTeamListLiveData();
        setH5LiveData();
        setWorkerListLiveData();
        setTemporaryEmploymentListLiveData();
        setJobTypeQuotationListLiveData();
    }


    /**
     * 初始化recyclerView,这里没有设置adapter，那是因为我们在后面进行设置，因为这里是有七个列表，所以我们需要每次进行切换的时候设置adapter，来进行适配
     */
    private void initRecyclerView() {
        mBinding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        mBinding.recyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                loadDataForTab(mTabPage,false);
            }

            @Override
            public void onLoadMore() {
                loadDataForTab(mTabPage,true);
            }
        });
    }

    /**
     * 初始化劳务用工的adapter,包含点击之后需要跳转的地方
     */
    private void setLaborAdapter(){
        mAdapter = new LaborServiceAndEmploymentAdapter(getContext(), null);
        mAdapter.setOnItemClick(new AdapterOnItemClick<LabourServiceAndEmploymentEntity>() {
            @Override
            public void onItemClick(LabourServiceAndEmploymentEntity labourServiceAndEmploymentEntity, int position) {
                ActivityJump.jumpToActivityForResult(getActivity(),LaborServiceAndEmploymentDetailActivity.class,0, Pair.create("no",labourServiceAndEmploymentEntity.getNo()),Pair.create("workNo",labourServiceAndEmploymentEntity.getWorkNo()),Pair.create("workName",labourServiceAndEmploymentEntity.getCategoryName()), Pair.create("isFocus",labourServiceAndEmploymentEntity.getIsFocus()),Pair.create("isApply",labourServiceAndEmploymentEntity.isApply()),Pair.create("mMomentNo",labourServiceAndEmploymentEntity.getUserNo()),Pair.create("workNameForList",labourServiceAndEmploymentEntity.getWorkName()),Pair.create("employmentType",labourServiceAndEmploymentEntity.getEmploymentType()),Pair.create("imId",labourServiceAndEmploymentEntity.getImId()));
            }
        });
    }

    /**
     * 初始化工程公司的adapter,包含点击之后需要跳转的地方
     */
    private void setCompanyAdapter(){
        adapterCompany = new EngineeringCompanyAdapter(getContext(),null, Glide.with(this));
        adapterCompany.setOnItemClick(new AdapterOnItemClick<EngineeringCompanyEntity>() {
            @Override
            public void onItemClick(EngineeringCompanyEntity entity, int position) {
                if (TextUtils.isEmpty(entity.getId())) {
                    ToastUtil.show(getActivity(), "企业店铺id不能为空");
                    return;
                }
                WebsiteInfoActivity.start(getActivity(), entity.getNo(), WebsiteInfoActivity.WEBSITE_FOR_COMPANY);
            }
        });
    }

    /**
     * 初始化班组工队的adapter,包含点击之后需要跳转的地方
     */
    private void setClassGroupAdapter(){
        findPackersClassGroupAdapter = new FindPackersAdapter(getActivity(), null, Glide.with(this),false);
        findPackersClassGroupAdapter.setOnItemClick(new AdapterOnItemClick<FindPackersEntity>() {
            @Override
            public void onItemClick(FindPackersEntity findPackersEntity, int position) {
                mViewModel.getH5Url(findPackersEntity.getNo());
            }
        });
    }

    /**
     * 初始化施工工队的adapter,包含点击之后需要跳转的地方
     */
    private void setBuildAdapter(){
        findPackersBuildAdapter = new FindPackersAdapter(getActivity(), null, Glide.with(this),true);
        findPackersBuildAdapter.setOnItemClick(new AdapterOnItemClick<FindPackersEntity>() {
            @Override
            public void onItemClick(FindPackersEntity findPackersEntity, int position) {
                mViewModel.getH5Url(findPackersEntity.getNo());
            }
        });
    }

    /**
     * 初始化工人关注的adapter,包含点击之后需要跳转的地方
     */
    private void setWorkerAdapter(){
        findPeopleAdapter = new FindPeopleAdapter(getContext(), null, Glide.with(this));
        findPeopleAdapter.setOnItemClick(new AdapterOnItemClick<FindPeopleEntity>() {
            @Override
            public void onItemClick(FindPeopleEntity findPeopleEntity, int position) {
                FindPeopleDetailActivity.start(getContext(), findPeopleEntity.getNo());
            }
        });
    }

    /**
     * 初始化临时用工关注的adapter,包含点击之后需要跳转的地方
     */
    private void setTemporaryEmploymentAdapter(){
        adapter = new PackersEmploymentAdapter(getContext(), null, 0);
        adapter.setOnItemClick(new AdapterOnItemClick<EmploymentEntity>() {
            @Override
            public void onItemClick(EmploymentEntity employmentEntity, int position) {
                EmploymentDetailActivity.startForResult(getActivity(), employmentEntity.getNo(), employmentEntity.getProjectName(),employmentEntity.isIsApply(),0);
            }
        });
    }

    /**
     * 初始化工种报价关注的adapter,包含点击之后需要跳转的地方
     */
    private void setJobTypeQuotationAdapter(){
        adapterQuotePrice = new QuotePriceListAdapter(getActivity(), null);
        adapterQuotePrice.setOnItemClick(new AdapterOnItemClick<TeamPriceItemEntity>() {
            @Override
            public void onItemClick(TeamPriceItemEntity teamPriceItemEntity, int position) {
                TeamOfferDetailActivity.start(getActivity(), teamPriceItemEntity.getNo());
            }
        });
    }

    /**
     * 这里是请求网络需要实现的方法，以type来判断我们需要请求哪一个接口
     * @param type 0 施工工队 1 班组工队(可以看到0和1是在一个case下，那是因为我们在这里请求的接口是同一个，并且和我们的type统一，即0 施工工队 1 班组工队，所以我们在这里传进去的参数为type)
     *             2 找工人 3 临时用工 4 工种报价 5 劳务用工 6 工程公司
     * @param isLoadMore 这里和我们的全局变量一样，是判断是否加载更多的一个依据
     */
    private void loadDataForTab(int type,boolean isLoadMore){
        switch (type){
            case 0:
            case 1:
                loadTeamData(type,isLoadMore);
                break;
            case 2:
                loadWorkerData(isLoadMore);
                break;
            case 3:
                loadTemporaryEmploymentData(isLoadMore);
                break;
            case 4:
                loadJobTypeQuotationData(isLoadMore);
                break;
            case 5:
                loadData(isLoadMore);
                break;
            case 6:
                loadCompanyData(isLoadMore);
                break;
            default:
                break;
        }
    }

    /**
     * 刚刚我们提到，这整个界面有7个列表，这里我们为了省时间就写在了一个界面上(其实这是不正确的，这违背了单一原则),所以我们在这里去设置对应的adapter
     * @param type 0 施工工队 1 班组工队 2 找工人 3 临时用工 4 工种报价 5 劳务用工 6 工程公司
     */
    private void setAdapterForTab(int type){
        switch (type){
            case 0:
                mBinding.recyclerView.setAdapter(findPackersBuildAdapter);
                break;
            case 1:
                mBinding.recyclerView.setAdapter(findPackersClassGroupAdapter);
                break;
            case 2:
                mBinding.recyclerView.setAdapter(findPeopleAdapter);
                break;
            case 3:
                mBinding.recyclerView.setAdapter(adapter);
                break;
            case 4:
                mBinding.recyclerView.setAdapter(adapterQuotePrice);
                break;
            case 5:
                mBinding.recyclerView.setAdapter(mAdapter);
                break;
            case 6:
                mBinding.recyclerView.setAdapter(adapterCompany);
                break;
            default:
                break;
        }
    }

    /**
     * 加载劳务用工的网络请求
     * @param isLoadMore 作为是否加载更多的一个依据，以此来更新对应属性
     */
    private void loadData(boolean isLoadMore){
        this.isLoadMore = isLoadMore;
        if (isLoadMore){
            page++;
        }else {
            page = 1;
        }
        Map<String,Object> map = new HashMap<>();
        map.put("limit",15);
        map.put("page",page);
        mViewModel.signUpTerm(map);
    }

    /**
     * 加载工程公司的网络请求
     * @param isLoadMore 作为是否加载更多的一个依据，以此来更新对应属性
     */
    private void loadCompanyData(boolean isLoadMore){
        this.isLoadMoreCompany = isLoadMore;
        if (isLoadMore){
            pageCompany++;
        }else {
            pageCompany = 1;
        }
        Map<String,Object> map = new HashMap<>();
        map.put("limit",15);
        map.put("page",pageCompany);
        mViewModel.getCompanyList(map);
    }

    /**
     * 加载班组工队或者施工工队的网络请求
     * @param isLoadMore 作为是否加载更多的一个依据，以此来更新对应属性
     * @param type 这里传入这个参数还是为了去请求对应的参数
     */
    private void loadTeamData(int type,boolean isLoadMore){
        Map<String,Object> map = new HashMap<>();
        if (mTabPage == 0){
            this.isLoadMoreTeamBuild = isLoadMore;
            if (isLoadMore){
                pageTeamBuild++;
            }else {
                pageTeamBuild = 1;
            }
            map.put("page",pageTeamBuild);
        }else if (mTabPage == 1){
            this.isLoadMoreTeamClassGroup = isLoadMore;
            if (isLoadMore){
                pageTeamClassGroup++;
            }else {
                pageTeamClassGroup = 1;
            }
            map.put("page",pageTeamClassGroup);
        }
        map.put("limit",15);
        map.put("teamType",type);
        mViewModel.getTeamList(map);
    }

    /**
     * 加载工人关注的网络请求
     * @param isLoadMore 作为是否加载更多的一个依据，以此来更新对应属性
     */
    private void loadWorkerData(boolean isLoadMore){
        this.isLoadMoreWorker = isLoadMore;
        if (isLoadMore){
            pageWorker++;
        }else {
            pageWorker = 1;
        }
        Map<String,Object> map = new HashMap<>(2);
        map.put("limit",15);
        map.put("page", pageWorker);
        mViewModel.getWorkerList(map);
    }

    /**
     * 加载临时用工的网络请求
     * @param isLoadMore 作为是否加载更多的一个依据，以此来更新对应属性
     */
    private void loadTemporaryEmploymentData(boolean isLoadMore){
        this.isLoadMoreTemporaryEmployment = isLoadMore;
        if (isLoadMore){
            pageTemporaryEmployment++;
        }else {
            pageTemporaryEmployment = 1;
        }
        Map<String,Object> map = new HashMap<>(2);
        map.put("limit",15);
        map.put("page", pageTemporaryEmployment);
        mViewModel.getTemporaryEmploymentList(map);
    }

    /**
     * 加载工种报价的网络请求
     * @param isLoadMore 作为是否加载更多的一个依据，以此来更新对应属性
     */
    private void loadJobTypeQuotationData(boolean isLoadMore){
        this.isLoadMoreQuotePrice = isLoadMore;
        if (isLoadMore){
            pageQuotePrice++;
        }else {
            pageQuotePrice = 1;
        }
        Map<String,Object> map = new HashMap<>(2);
        map.put("limit",15);
        map.put("page", pageQuotePrice);
        mViewModel.getJobTypeQuotationList(map);
    }

    /**
     * 这里是更新网络请求状态的liveData,一共包括三个状态，加载，成功或失败
     */
    private void setStatusLiveData(){
        mViewModel.loadingLiveData.observe(getViewLifecycleOwner(), aBoolean -> DialogHelper.showProgressDialog(getContext(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false));
        mViewModel.successLiveData.observe(getViewLifecycleOwner(), aBoolean -> DialogHelper.dismissProgressDialog());
        mViewModel.errorLiveData.observe(getViewLifecycleOwner(), aBoolean -> DialogHelper.dismissProgressDialog());
    }

    /**
     * 加载重新请求，这里的事件主要在于我们到详情去做了操作，当前界面需要更新来产生回调
     */
    private void setStateLiveData(){
        IntelligentAttentionActivity intelligentAttentionActivity = (IntelligentAttentionActivity) getActivity();
        if (intelligentAttentionActivity != null) {
            intelligentAttentionActivity.liveData.observe(getViewLifecycleOwner(), integer -> loadData(false));
        }
    }

    /**
     * 劳务用工数据返回，需要设置adapter
     */
    private void setLaborListLiveData(){
        mViewModel.mFollowSuccessLiveData.observe(getViewLifecycleOwner(), labourServiceAndEmploymentEntities -> {
            if (isLoadMore) {
                if (labourServiceAndEmploymentEntities != null && labourServiceAndEmploymentEntities.size() > 0) {
                    mAdapter.addDatas(labourServiceAndEmploymentEntities);
                }
                if (labourServiceAndEmploymentEntities != null) {
                    mBinding.recyclerView.setNoMore(labourServiceAndEmploymentEntities.size() < 10);
                }
                mBinding.recyclerView.setVisibility(View.VISIBLE);
            } else {
                mBinding.recyclerView.refreshComplete();
                if (labourServiceAndEmploymentEntities != null && labourServiceAndEmploymentEntities.size() > 0) {
                    mBinding.emptyView.setVisibility(View.GONE);
                    mAdapter.setDatas(labourServiceAndEmploymentEntities);
                    mBinding.recyclerView.smoothScrollToPosition(0);
                    if (labourServiceAndEmploymentEntities.size() < NumberConstant.NUMBER_TEN) {
                        mBinding.recyclerView.setNoMore(true);
                    }
                } else {
                    mAdapter.clearDatas();
                    mBinding.emptyView.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    /**
     * 工程公司数据返回，需要设置adapter
     */
    private void setCompanyListLiveData(){
        mViewModel.mFollowCompanyLiveData.observe(getViewLifecycleOwner(), engineeringCompanyEntities -> {
            if (isLoadMoreCompany) {
                if (engineeringCompanyEntities != null && engineeringCompanyEntities.size() > 0) {
                    adapterCompany.addDatas(engineeringCompanyEntities);
                }
                if (engineeringCompanyEntities != null) {
                    mBinding.recyclerView.setNoMore(engineeringCompanyEntities.size() < 10);
                }
                mBinding.recyclerView.setVisibility(View.VISIBLE);
            } else {
                mBinding.recyclerView.refreshComplete();
                if (engineeringCompanyEntities != null && engineeringCompanyEntities.size() > 0) {
                    mBinding.emptyView.setVisibility(View.GONE);
                    adapterCompany.setDatas(engineeringCompanyEntities);
                    mBinding.recyclerView.smoothScrollToPosition(0);
                    if (engineeringCompanyEntities.size() < NumberConstant.NUMBER_TEN) {
                        mBinding.recyclerView.setNoMore(true);
                    }
                } else {
                    adapterCompany.clearDatas();
                    mBinding.emptyView.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    /**
     * 施工工队和班组工队数据返回，需要设置adapter
     */
    private void setTeamListLiveData(){
        mViewModel.mFollowTeamLiveData.observe(getViewLifecycleOwner(), findPackersEntities -> {
            if (mTabPage == 0){
                if (isLoadMoreTeamBuild) {
                    if (findPackersEntities != null && findPackersEntities.size() > 0) {
                        findPackersBuildAdapter.addDatas(findPackersEntities);
                    }
                    if (findPackersEntities != null) {
                        mBinding.recyclerView.setNoMore(findPackersEntities.size() < 10);
                    }
                    mBinding.recyclerView.setVisibility(View.VISIBLE);
                } else {
                    mBinding.recyclerView.refreshComplete();
                    if (findPackersEntities != null && findPackersEntities.size() > 0) {
                        mBinding.emptyView.setVisibility(View.GONE);
                        findPackersBuildAdapter.setDatas(findPackersEntities);
                        mBinding.recyclerView.smoothScrollToPosition(0);
                        if (findPackersEntities.size() < NumberConstant.NUMBER_TEN) {
                            mBinding.recyclerView.setNoMore(true);
                        }
                    } else {
                        findPackersBuildAdapter.clearDatas();
                        mBinding.emptyView.setVisibility(View.VISIBLE);
                    }
                }
            }else if (mTabPage == 1){
                if (isLoadMoreTeamClassGroup) {
                    if (findPackersEntities != null && findPackersEntities.size() > 0) {
                        findPackersClassGroupAdapter.addDatas(findPackersEntities);
                    }
                    if (findPackersEntities != null) {
                        mBinding.recyclerView.setNoMore(findPackersEntities.size() < 10);
                    }
                    mBinding.recyclerView.setVisibility(View.VISIBLE);
                } else {
                    mBinding.recyclerView.refreshComplete();
                    if (findPackersEntities != null && findPackersEntities.size() > 0) {
                        mBinding.emptyView.setVisibility(View.GONE);
                        findPackersClassGroupAdapter.setDatas(findPackersEntities);
                        mBinding.recyclerView.smoothScrollToPosition(0);
                        if (findPackersEntities.size() < NumberConstant.NUMBER_TEN) {
                            mBinding.recyclerView.setNoMore(true);
                        }
                    } else {
                        findPackersClassGroupAdapter.clearDatas();
                        mBinding.emptyView.setVisibility(View.VISIBLE);
                    }
                }
            }
        });
    }

    /**
     * 工人关注数据返回，需要设置adapter
     */
    private void setWorkerListLiveData(){
        mViewModel.mFollowWorkerLiveData.observe(getViewLifecycleOwner(), findPeopleEntities -> {
            if (isLoadMoreWorker) {
                if (findPeopleEntities != null && findPeopleEntities.size() > 0) {
                    findPeopleAdapter.addDatas(findPeopleEntities);
                }
                if (findPeopleEntities != null) {
                    mBinding.recyclerView.setNoMore(findPeopleEntities.size() < 10);
                }
                mBinding.recyclerView.setVisibility(View.VISIBLE);
            } else {
                mBinding.recyclerView.refreshComplete();
                if (findPeopleEntities != null && findPeopleEntities.size() > 0) {
                    mBinding.emptyView.setVisibility(View.GONE);
                    findPeopleAdapter.setDatas(findPeopleEntities);
                    mBinding.recyclerView.smoothScrollToPosition(0);
                    if (findPeopleEntities.size() < NumberConstant.NUMBER_TEN) {
                        mBinding.recyclerView.setNoMore(true);
                    }
                } else {
                    findPeopleAdapter.clearDatas();
                    mBinding.emptyView.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    /**
     * 临时用工关注数据返回，需要设置adapter
     */
    private void setTemporaryEmploymentListLiveData(){
        mViewModel.mFollowTemporaryEmploymentLiveData.observe(getViewLifecycleOwner(), employmentEntities -> {
            if (isLoadMoreTemporaryEmployment) {
                if (employmentEntities != null && employmentEntities.size() > 0) {
                    adapter.addDatas(employmentEntities);
                }
                if (employmentEntities != null) {
                    mBinding.recyclerView.setNoMore(employmentEntities.size() < 10);
                }
                mBinding.recyclerView.setVisibility(View.VISIBLE);
            } else {
                mBinding.recyclerView.refreshComplete();
                if (employmentEntities != null && employmentEntities.size() > 0) {
                    mBinding.emptyView.setVisibility(View.GONE);
                    adapter.setDatas(employmentEntities);
                    mBinding.recyclerView.smoothScrollToPosition(0);
                    if (employmentEntities.size() < NumberConstant.NUMBER_TEN) {
                        mBinding.recyclerView.setNoMore(true);
                    }
                } else {
                    adapter.clearDatas();
                    mBinding.emptyView.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    /**
     * 工种报价关注数据返回，需要设置adapter
     */
    private void setJobTypeQuotationListLiveData(){
        mViewModel.mFollowJobTypeQuotationLiveData.observe(getViewLifecycleOwner(), teamPriceItemEntities -> {
            if (isLoadMoreQuotePrice) {
                if (teamPriceItemEntities != null && teamPriceItemEntities.size() > 0) {
                    adapterQuotePrice.addDatas(teamPriceItemEntities);
                }
                if (teamPriceItemEntities != null) {
                    mBinding.recyclerView.setNoMore(teamPriceItemEntities.size() < 10);
                }
                mBinding.recyclerView.setVisibility(View.VISIBLE);
            } else {
                mBinding.recyclerView.refreshComplete();
                if (teamPriceItemEntities != null && teamPriceItemEntities.size() > 0) {
                    mBinding.emptyView.setVisibility(View.GONE);
                    adapterQuotePrice.setDatas(teamPriceItemEntities);
                    mBinding.recyclerView.smoothScrollToPosition(0);
                    if (teamPriceItemEntities.size() < NumberConstant.NUMBER_TEN) {
                        mBinding.recyclerView.setNoMore(true);
                    }
                } else {
                    adapterQuotePrice.clearDatas();
                    mBinding.emptyView.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    /**
     * 去到工队的详情页，h5页面
     */
    private void setH5LiveData(){
        mViewModel.mUrlLiveData.observe(getViewLifecycleOwner(), s -> {
            String[] split = s.split("----");
            com.swgk.core.common.utils.ActivityJump.startActivity(PathTeam.TeamDetailActivity, Pair.create("no",split[1]),Pair.create("url",split[0]));
        });
    }
}
